import request from "@/utils/request";
import { API_ENDPOINTS } from "@/config/api";

// 评估问题接口
export interface AssessmentQuestion {
  id: number;
  question_text: string;
  description?: string;
  question_type: "multiple_choice" | "rating" | "text" | "scenario";
  category?: string;
  options?: Array<{
    value: any;
    label: string;
    description?: string;
  }>;
  ability_type?: string;
  rating_min?: number;
  rating_max?: number;
  rating_min_label?: string;
  rating_max_label?: string;
  scenario_description?: string;
  hint?: string;
}

// 评估答案接口
export interface AssessmentAnswer {
  question_id: number;
  answer_value: any;
  answer_text?: string | null;
  response_time?: number;
}

// 提交评估参数
export interface SubmitAssessmentParams {
  answers: AssessmentAnswer[];
  duration?: number;
  completed_at?: string;
}

// 评估结果接口
export interface AssessmentResult {
  id: number;
  overall_score: number;
  abilities: Array<{
    ability_type: string;
    ability_name: string;
    score: number;
    description: string;
  }>;
  suggestions: Array<{
    title: string;
    description: string;
    actions?: string[];
  }>;
  created_at: string;
}

// 评估相关API
export const assessmentApi = {
  // 获取评估问题
  getAssessmentQuestions() {
    return request.get<AssessmentQuestion[]>(
      API_ENDPOINTS.ASSESSMENT.QUESTIONS
    );
  },

  // 提交评估答案
  submitAssessment(userId: number, params: SubmitAssessmentParams) {
    return request.post<{ id: number }>(
      API_ENDPOINTS.ASSESSMENT.SUBMIT(userId),
      params
    );
  },

  // 获取评估结果
  getAssessmentResult(assessmentId: string) {
    return request.get<AssessmentResult>(
      API_ENDPOINTS.ASSESSMENT.RESULT(assessmentId)
    );
  },
};
